import { fetch } from '@/little/fetch';

export const loginByCode = (code, type = 1) => fetch.post('/v1/member/login', { code, type });
export const codeByMobile = (code) => fetch.post('/v1/member/codeBindMobile', { code, type: 2 });
export const setMemberInfo = (args) => fetch.post('/v1/member/basic', args);
export const memberInfo = () =>
    fetch.get('/v1/member/basic').then(
        (res) =>
            new Promise((resolve, _) => {
                const current_address = res.data.address_meta?.find((item) => item?.isDefault == true) ?? res.data.address_meta[0];
                if (current_address) {
                    uni.$lz.vuex('$current_address', current_address);
                }
                uni.$lz.vuex('$userInfo', res.data);
                resolve(res);
            })
    );
export const saveAddress = (args) => fetch.post(`/v1/member/address`, args);
export const defaultAddress = (id) => fetch.put(`/v1/member/address/${id}`, {});
export const removeAddress = (id) => fetch.delete(`/v1/member/address/${id}`);
